package com.springBoot.springBootSysCore.modules.controller.api;

import com.springBoot.springBootSysCore.modules.controller.web.base.SimpleBaseController;
import com.springBoot.springBootSysCore.modules.services.SysAppLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by timo on 2017/11/28.
 */
@RestController
@RequestMapping("${apiPath}/login")
public class LoginControllerApi extends SimpleBaseController{
    @Autowired
    private SysAppLoginService loginService;
    /**
     * 注册
     * @return
     */
    @RequestMapping(value="register",method= RequestMethod.POST)
    public Object register(
            @RequestParam(required=true)String phone,
            @RequestParam(required=true)String msgCode,
            @RequestParam(required=false,defaultValue = "111111")String passWord){
        return loginService.register(phone,msgCode,passWord);
    }

    /**
     * 检查图像验证码
     * @param code
     * @return
     */
    @RequestMapping(value="validateCode",method=RequestMethod.POST)
    public Object validateCode(
            @RequestParam(required=true)String code){
        return loginService.validateCode(code);
    }

    /**
     * 忘记密码
     * @return
     */
    @RequestMapping(value="updateForgetPwd",method=RequestMethod.POST)
    public Object updateForgetPwd(
            @RequestParam(required=true)String phone,
            @RequestParam(required=true)String msgCode,
            @RequestParam(required=true)String passWord){
        return loginService.updateForgetPwd(phone,msgCode,passWord);
    }
    /**
     *  登录
     * @return
     */
    @RequestMapping(value="login",method=RequestMethod.POST)
    public Object login(
            @RequestParam(required=true)String phone,
            @RequestParam(required=false)String msgCode,
            @RequestParam(required=true)String passWord
            ){
        return loginService.login(phone,msgCode,passWord);
    }

    /**
     * 退出登录
     * @return
     */
    @RequestMapping(value="loginOut",method=RequestMethod.POST)
    public Object loginOut(){
        return loginService.loginOut();
    }

    /**
     * 上传头像
     * @return
     */
    @RequestMapping(value="uploadPhoto",method=RequestMethod.POST)
    public Object uploadPhoto(
            @RequestParam(required=true)String userId,HttpServletRequest request){
        return loginService.uploadPhoto(userId,request);
    }
    /**
     * 获取系统时间戳
     * @param phone
     * @returns
     */
    @RequestMapping(value="getCurSysTimestamp",method=RequestMethod.POST)
    public Object getCurSysTimestamp( @RequestParam(required=true)String phone){
        return loginService.getCurSysTimestamp(phone);
    }
    /**
     * 获取验证码
     * @return
     * @throws Exception
     */
    @RequestMapping(value="getMsgCode",method=RequestMethod.POST)
    public Object getMsgCode(
            @RequestParam(required=true)String phone,
            @RequestParam(required=true)String msgCodeType,
            @RequestParam(required=true)String secret) throws Exception{
        return loginService.getMsgCode(phone,msgCodeType,secret);
    }
}
